package joe.schmo.cards;

import org.biloxi.card.Card;
import org.biloxi.commands.Command;
import org.biloxi.commands.Filter;
import org.biloxi.commands.Listener;
import org.biloxi.commands.playcard.PlayCard;
import org.biloxi.commands.playcard.PlayCard.Result;
import org.biloxi.commands.playerlost.PlayerLost;
import org.biloxi.model.GameState;
import org.biloxi.model.card.CardInstance;
import org.biloxi.player.PlayerID;

public class DeityOfDeath extends Card{

	@Override
	public String getDescription() {
		return "When played kills opponents of controller of this spell.";
	}

	@Override
	public String getExtraText() {
		return "";
	}

	@Override
	public String getName() {
		return "Deity Of Death";
	}

	@Override
	public String[] getSubTypes() {
		return new String[]{"Deity"};
	}

	@Override
	public Type getType() {
		return Type.Creature;
	}

	@Override
	public void initCard(final CardInstance card, final GameState game) {
		/*
		 * Holy shit ouch. We need a DSL.
		 */
		cmds().playCard.do_(
				// Just when this card is played 
				new Filter<PlayCard.Result>(){
					public boolean allow(Result r) {
						return r.card == card;
					}
				}, 
				// "Lose" all opponents
				new Listener<PlayCard.Options, PlayCard.Result>(){
					public void handle(Command<PlayCard.Options, PlayCard.Result> c, PlayCard.Options o, PlayCard.Result r, GameState g) {
						for(PlayerID opponent : g.getOppenents(o.card.getControllerID()))
							g.do_(cmds().playerLost, new PlayerLost.Options(opponent));
					}
				}
		);
	}
	
}
